version 17
log using mineprod, text replace
set linesize 100
set more off
*****************************************************************
* Program purpose:
* Estimate effect of 8 hour day on productivity in IL coal.
* Data set = mines 1891-1905 from Illinois BLS.
* Fixed effects for mines.
* Fixed effects or trends for years.
*****************************************************************

* Read data =====================================================

use illinoismines.dta, clear
* Descriptive statistics of data as read
describe
summarize

* Edit data to fix aggregation issues ===========================

* Pana Coal company mines 1 & 2, Christian County, are reported together 
* in most years but not in 1894.  Merge data for 1894.
replace outtotal = 175000 + 250000 if year==1894 & cmnumber==21101
replace empminers = 130 + 175 if year==1894 & cmnumber==21101
replace empothers = 38 + 50 if year==1894 & cmnumber==21101
replace empboys = 6 + 10 if year==1894 & cmnumber==21101
replace days = (240+260)/2 if year==1894 & cmnumber==21101
drop if year==1894 & cmnumber==21107
drop if year>1903 & cmnumber==21107

* Devlin Coal company mines 1, 2, & 3, Marshall county, are reported
* inconsistently.  Merge data for all years.
replace outtotal = 56332+400+200 if year==1894 & cmnumber==123119
replace empminers = 300+8+8 if year==1894 & cmnumber==123119
replace empothers = 100+4+4 if year==1894 & cmnumber==123119
drop if year==1894 & cmnumber==123120
drop if year==1894 & cmnumber==123121
replace empothers = 100+4+2 if year==1895 & cmnumber==123119
replace outtotal = 94405+163731 if year==1897 & cmnumber==123119
replace empminers = 200+400 if year==1897 & cmnumber==123119
replace empothers = 22+63 if year==1897 & cmnumber==123119
drop if year==1897 & cmnumber==123120
replace outtotal = 10000+207987 if year==1898 & cmnumber==123119
replace emptotal = 89+475 if year==1898 & cmnumber==123119
drop if year==1898 & cmnumber==123120
replace outtotal = 207714+28527 if year==1900 & cmnumber==123119
replace emptotal = 434+73 if year==1900 & cmnumber==123119
drop if year==1900 & cmnumber==123120
replace outtotal = 215908+65605 if year==1901 & cmnumber==123119
replace emptotal = 478+100 if year==1901 & cmnumber==123119
drop if year==1901 & cmnumber==123120
replace outtotal = 288278+26285 if year==1902 & cmnumber==123119
replace emptotal = 529+100 if year==1902 & cmnumber==123119
drop if year==1902 & cmnumber==123120

* Jeffords Bros. mines 1 & 2, Peoria county, are reported separately
* in 1891 and 1898 but together in all other years.  Merge data for 
* 1891 and 1898.
replace outtotal = 2100+4643 if year==1891 & cmnumber==143101
replace empminers = 4+10 if year==1891 & cmnumber==143101
replace empothers = 2+4 if year==1891 & cmnumber==143101
replace days = (130+115)/2 if year==1891 & cmnumber==143101
drop if year==1891 & cmnumber==143102
replace outtotal = 23689+646 if year==1898 & cmnumber==143101
replace emptotal = 16+16 if year==1898 & cmnumber==143101
replace days = (59+17)/2 if year==1898 & cmnumber==143101
drop if year==1898 & cmnumber==143102

* Generate variables needed for regression ======================

generate employ = empminers+empothers // data available 1891-1895
replace employ = (empuwin+empusum+empawin+empasum)/2 if year==1896
replace employ = emptotal if year>1896
generate prod = outtotal/employ/days
generate lprod = log(prod)
generate mach = outmach/outtotal //data available through 1901
replace mach = 1 - outhand/outtotal if year>=1902
generate mytrend = year-1898
generate year1898 = (year==1898) // transition year
generate hrs8 = (year>1898) // 8 hour day in effect
generate ldays = log(days)
generate lemploy = log(employ)

label variable lprod "Log output per worker per day"
label variable mach "Fraction of coal mined by machine"
label variable mytrend "Time trend, 1898=zero"

* Create a flag indicating mine was a "shipping" mine for at least 
* one year.  Note that "market" not reported for 1897-1901.
sort cmnumber year
by cmnumber: egen shipping = max(market=="Shipping" | market=="Both")

* Compute descriptive statistics of regression sample ===========

generate notsmall = employ>=10 & days>=20
keep if (1- missing(lprod,mach)) & notsmall

* Table 4
summarize prod mach days employ mytrend year shipping atconf

* How does sample compare with Illinois universe in 1898,
* as reported in IBLS, "Coal in Illinois" (1898, p.19)?
summarize outtotal employ if year==1898, detail

* What is the relation between shipping mines and mines
* represented at 1898 conference?
tab shipping atconf if year==1898
 
* Set up for panel analysis =====================================

xtset cmnumber year
xtdescribe
xtsum prod mach days employ

* How many mines are observed both before and after switch to 8-hour
* day in 1898?  (See upper right corner of transition matrix.)
xttrans hrs8, freq

* Compute panel estimates, entire sample ========================

* Year dummies for Figure 5
xtreg lprod  mach ib1898.year, fe vce(robust)

* Table 5 columns 1 and 2
xtreg lprod  hrs8 mach mytrend year1898, fe vce(robust)
xtreg lprod  hrs8 mach mytrend year1898 ldays lemploy, fe vce(robust)

* Compute panel estimates, shipping mines only ==================

* Table 5 columns 3 and 4
xtreg lprod  hrs8 mach mytrend year1898 if shipping, fe vce(robust)
xtreg lprod  hrs8 mach mytrend year1898 ldays lemploy ///
  if shipping, fe vce(robust) 

* Compute panel estimates, mines represented at conference only =

* Table 5 columns 5 and 6
xtreg lprod  hrs8 mach mytrend year1898 if atconf, fe vce(robust)
xtreg lprod  hrs8 mach mytrend year1898 ldays lemploy ///
  if atconf, fe vce(robust)
  
* Robustness checks =============================================

* Compute panel estimates, allowing different trend after 1898
generate mytrendafter = mytrend * (year>1898)  
label variable mytrendafter "Change in time trend after 1898"
xtreg lprod  hrs8 mach mytrend mytrendafter year1898, fe vce(robust)
xtreg lprod  hrs8 mach mytrend mytrendafter year1898 ldays ///
  lemploy, fe vce(robust)
xtreg lprod  hrs8 mach mytrend mytrendafter year1898 ///
  if shipping, fe vce(robust)
xtreg lprod  hrs8 mach mytrend mytrendafter year1898 ldays ///
  lemploy if shipping, fe vce(robust)
xtreg lprod  hrs8 mach mytrend mytrendafter year1898 ///
  if atconf, fe vce(robust)
xtreg lprod  hrs8 mach mytrend mytrendafter year1898 ldays ///
  lemploy if atconf, fe vce(robust)
  
* End program ===================================================

clear
log close
exit


